package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/sysRisk"
	sysRisk2 "git.900sui.cn/kc/rpcinterface/interface/sysRisk"
	"github.com/streadway/amqp"
	"strconv"
	"strings"
)

//风控系统商家地区信息改变
func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("sysrisk.log.busAreaChangeQueue"))
	rpcRisk := new(sysRisk.BusBasic).Init()

	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("sysrisk.queue.busAreaChangeQueue"), func(msg amqp.Delivery) {
		dataStr := string(msg.Body)
		dataSlice := strings.Split(dataStr, "_")
		if len(dataSlice) >= 7 {
			//riskBusId_省id_市id_区id_街道id_商圈Id_综合体Id
			sData := &sysRisk2.ArgsChangeBusArea{}
			sData.RiskBusId, _ = strconv.Atoi(dataSlice[0])
			sData.Pid, _ = strconv.Atoi(dataSlice[1])
			sData.Cid, _ = strconv.Atoi(dataSlice[2])
			sData.Did, _ = strconv.Atoi(dataSlice[3])
			sData.Tid, _ = strconv.Atoi(dataSlice[4])
			sData.DistrictId, _ = strconv.Atoi(dataSlice[5])
			sData.SyntId, _ = strconv.Atoi(dataSlice[6])
			reply := false

			if err := rpcRisk.ChangeBusArea(context.Background(), sData, &reply); err != nil {
				utils.Logerr.Printf("更改商户地区信息失败，riskBusId：【%s】失败信息：%s\n", dataStr, err.Error())
				return
			} else {
				utils.Logerr.Println("更改商户地区信息成功, 数据：", dataStr)
			}
			return
		}
	})

	if err != nil {
		panic(err)
	}
}
